//Accepted
#include <cstdio>
#include <cmath>
int n, a[10000], i, j, k, p, x;

bool read(){
	scanf("%d", &n);
	for(i=0;i<n;++i)scanf("%d", &a[i]);
	return n!=0;
}
int ant(int z){
	--z;
	if(z<0)z=n-1;
	return a[z];
}
int prox(int z){
	++z;
	if(z==n)z=0;
	return a[z];
}
void process(){
	p=1;
	x=1;
	for(i=0;x;i=(i+1)%n){
		if(ant(i)<a[i]&&a[i]>prox(i))x=0;
	}
	--i;
	if(i<0)i+=n;
	
	j=i;
	i=(i+1)%n;
	for( ;i!=j;  i=(i+1)%n ){
		if(x){
			if(ant(i)<a[i]&&a[i]>prox(i)){
				++p;
				x=0;
			}
		}
		else{
			if(ant(i)>a[i]&&a[i]<prox(i)){
				++p;
				x=1;
			}
		}
	}
	printf("%d\n", p);
	
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(read())process();
	return 0;
}

